package com.gaomall.seckill.service.impl;

import com.gaomall.seckill.domain.Users;
import com.gaomall.seckill.mapper.UsersMapper;
import com.gaomall.seckill.service.IUserService;
import com.gaomall.seckill.utils.MD5Util;
import com.gaomall.seckill.utils.ResultVOUtil;
import com.gaomall.seckill.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
//@Transactional(readOnly = true)
public class UserServiceImpl implements IUserService {

    @Autowired
    UsersMapper usersMapper;

    @Override
    public ResultVO<Users> login(String telphone, String password) {

//        int resultCount = userMapper.checkTelphone(telphone);
//        if(resultCount == 0 ){
//            return ResultVOUtil.error("手机号不存在");
//        }
//
//        String md5Password = MD5Util.MD5EncodeUtf8(password);
//        Users user  = userMapper.selectLogin(telphone, md5Password);
//        if(user == null){
//            return ResultVOUtil.error("手机号或密码错误");
//        }
//
//        user.setPasswd(org.apache.commons.lang3.StringUtils.EMPTY);
//
//        return ResultVOUtil.success("登录成功", user);
        return null;
    }

    @Override
    public ResultVO<String> register(Users users) {

        Users user = new Users();
        users.setTelphone("13601945597");
        users.setPasswd("123456");
        users.setNickName("gaodevops");
        users.setSalt("123456");
        users.setToken("123123123");
        users.setLastIp("192.168.1.1");
        users.setLastTime(new Date());

        // 插入数据
        usersMapper.insert(users);

        return null;
    }
}
